﻿using System;
using System.Collections.Generic;
using System.Text;
using FileSystem.Models;
using FileSystem.Services.IServices;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace FileSystem.ViewModels {
    /// <summary>
    /// 桌面图标小ViewModel
    /// </summary>
    public class IconViewModel : ViewModelBase {
        // ******** 构造函数

        /// <summary>
        /// 内容导航服务
        /// </summary>
        private IContentNavigationService _contentNavigationService;

        /// <summary>
        /// 桌面图标小ViewModel
        /// </summary>
        public IconViewModel(
            IContentNavigationService contentNavigationService) {
            _contentNavigationService = contentNavigationService;
        }

        // ******** 绑定属性
        /// <summary>
        /// 图标和图标名称
        /// </summary>
        public IconAndFont IconAndFont {
            get => _iconAndFont;
            set => Set(nameof(IconAndFont), ref _iconAndFont, value);
        }

        /// <summary>
        /// 图标和图标名称
        /// </summary>
        private IconAndFont _iconAndFont;

        // ******** 绑定命令

        /// <summary>
        /// 进入某个功能页面命令
        /// </summary>
        private RelayCommand _entryCommand;

        /// <summary>
        /// 进入某个功能页面命令
        /// </summary>
        public RelayCommand EntryCommand =>
            _entryCommand ?? (_entryCommand =
                new RelayCommand(() => EntryCommandFunction()));

        public void EntryCommandFunction() {
            // //TODO 这里改成带参数绑定命令
            // _contentNavigationService.NavigateToAsync(
            //     IconConstants.FontToPageKeyDictionary[
            //         IconConstants.FileSystemFont]);

            if (IconAndFont.Font == IconConstants.FileSystemFont)
                _contentNavigationService.NavigateToAsync(
                    IconConstants.FontToPageKeyDictionary[
                        IconConstants.FileSystemFont]);
            else if (IconAndFont.Font == IconConstants.PhysicalDiskBlockFont)
                _contentNavigationService.NavigateToAsync(
                    IconConstants.FontToPageKeyDictionary[
                        IconConstants.PhysicalDiskBlockFont]);
        }
    }

    /// <summary>
    /// 桌面图标小ViewModel常量
    /// </summary>
    public static class IconConstants {
        /// <summary>
        /// 图标名称常量
        /// </summary>
        public const string FileSystemFont = "文件系统";

        /// <summary>
        /// 图标名称常量
        /// </summary>
        public const string PhysicalDiskBlockFont = "物理磁盘块模拟";

        /// <summary>
        /// 图标名称常量-页面键字典.
        /// </summary>
        public static readonly Dictionary<string, string>
            FontToPageKeyDictionary = new Dictionary<string, string> {
                {FileSystemFont, ContentNavigationConstants.FileSystemPage}, {
                    PhysicalDiskBlockFont,
                    ContentNavigationConstants.PhysicalDiskBlockPage
                }
            };
    }
}